home *** CD-ROM | disk | FTP | other *** search
- #include "QD3DtoQTVR.h"
- #include "extern.h"
- #include "camera.h"
- #include "draw.h"
- #include "Panorama.h"
- #include "file.h"
- #include "AEVT.h"
- #include "MyMovies.h"
- #include "document.h"
-
- #define factor 32.0
-
- void MyConvert3DMFToPano(FSSpec *myFSS)
- {
- DocumentPtr theDocument;
-
- // Create the document record and make the view and camera
- theDocument = MyNewDocument();
- if (!theDocument)
- return;
-
- // Read the model and add it to the document record's group
- if(MyOpenFile(myFSS, theDocument)) {
- MyCloseDocument(theDocument);
- return;
- }
-
- // Set up the initial camera position for object rendering
- MyInitPanoCamera(theDocument);
-
- // Draw to the screen
- MyDrawOffScreen(theDocument);
- MyDrawOnScreen(theDocument);
-
- // Assign the Codec type
- theDocument->theCodecType = kMyCodec;
-
- // generate the pano frames
- MyGeneratePanoFrames(theDocument);
-
- // Clean up
- MyCloseDocument(theDocument);
- }
-
- void MyGeneratePanoFrames(DocumentPtr theDocument)
- {
- PicHandle thePict;
- float zAngle;
- long counter = 0;
- Str255 fName;
- GWorldPtr gw;
- GDHandle gd;
- FSSpec outSpec;
-
- GetGWorld(&gw, &gd);
- SetGWorld(theDocument->theWindow,nil);
-
- outSpec = theDocument->theFileSpec;
-
- for(zAngle = 360;zAngle >0; zAngle -= 30) {
- short i;
-
- if (Button())
- break;
-
- // Rotate camera for next shot
- MyRotateCameraY(theDocument, -30.0*kQ3Pi/180.0);
-
- // Render image
- SetGWorld(theDocument->theWindow,nil);
- MyDrawOffScreen(theDocument);
- MyDrawOnScreen(theDocument);
-
- // Get image and copy it to destination.
- SetGWorld(theDocument->drawContextOffscreen,nil);
- thePict = OpenPicture(&theDocument->drawContextOffscreen->portRect);
- LockPixels(theDocument->drawContextOffscreen->portPixMap);
- CopyBits((BitMap*)&theDocument->drawContextOffscreen->portPixMap,
- (BitMap*)&theDocument->drawContextOffscreen->portPixMap,
- &theDocument->drawContextOffscreen->portRect,
- &theDocument->drawContextOffscreen->portRect,
- srcCopy,NULL);
- UnlockPixels(theDocument->drawContextOffscreen->portPixMap);
- ClosePicture();
-
- // Create file name for next image.
- counter++;
- NumToString(counter,fName);
- if (counter >= 10)
- for(i = 0; i <= fName[0]; i++)
- outSpec.name[i] = fName[i];
- else {
- outSpec.name[0] = '\2';
- outSpec.name[1] = '0';
- outSpec.name[2] = fName[1];
- }
-
- // Save new image to file.
- MySavePICT(thePict,&outSpec);
- KillPicture(thePict);
- }
-
- // Clean up.
- SetGWorld(theDocument->theWindow,nil);
- MyDrawOffScreen(theDocument);
- MyDrawOnScreen(theDocument);
- SetGWorld(gw,gd);
- }
-
-
- OSErr MySavePICT(PicHandle picture,FSSpec *theSpec)
- {
- long bytes;
- OSErr err;
- short fRefNum;
-
- FSpDelete (theSpec);
- err = FSpCreate (theSpec, '3DVR', 'PICT', smCurrentScript);
- if(err)
- return err;
-
- err = FSpOpenDF (theSpec, fsRdWrPerm, &fRefNum);
- if(err)
- return err;
-
- bytes = 512;
- FSWrite(fRefNum,&bytes,(Ptr)NULL);
- HLock((Handle)picture);
- bytes = GetHandleSize((Handle)picture);
- FSWrite(fRefNum,&bytes,(Ptr)(*picture));
- HUnlock((Handle)picture);
- FSClose(fRefNum);
- FlushVol(theSpec->name,theSpec->vRefNum);
-
- return err;
- }
-
-